package pen_exam;

import java.util.HashMap;
import java.util.Objects;
import java.util.TreeMap;

public class HashMapTest {
    DoubleHeadListNode[] slots = new DoubleHeadListNode[16];
    int[] size = new int[16];
    class DoubleHeadListNode{
        public DoubleHeadListNode next;
        public int key;
        public int value;
        public DoubleHeadListNode( int key, int value) {
            this.key = key;
            this.value = value;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            DoubleHeadListNode that = (DoubleHeadListNode) o;
            return key == that.key && value == that.value && Objects.equals(next, that.next);
        }

        @Override
        public int hashCode() {
            return Objects.hash(key);
        }
    }
    public void put(int key,int value){
        DoubleHeadListNode cur = new DoubleHeadListNode(key,value);
        int index = cur.hashCode() % slots.length;
        if(slots[index] == null){
            slots[index] = cur;
            size[index]++;
        }else{
            DoubleHeadListNode temp = slots[index];
            while(temp.next != null) {
                if(temp.key == cur.key){
                    temp.value = cur.value;
                    return;

                }
                temp = temp.next;
            }
            temp.next = cur;
            size[index]++;
            if(size[index] >= 8){
                //树化
            }
        }
    }
}
